package com.example.ParseXML;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.example.lib.EpubUTIL;
import com.google.gson.Gson;

import android.app.ProgressDialog;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class AsynParseXML extends AsyncTask<String, Void, String> {
	private Handler handler;
	private ProgressDialog progressDialog;
	private Context context;
	public boolean end = false;
	Gson gson = new Gson();
	public AsynParseXML(Context context, Handler handler) {
		super();
		this.handler = handler;
		this.context = context;
	}

	@Override
	protected String doInBackground(String... params) {
		ParseContainer mcontainer = new ParseContainer(params[0]);
		String m = gson.toJson(mcontainer.getContainer());
		return m;
	}

	@Override
	protected void onPreExecute() {
		progressDialog = new ProgressDialog(context);
		progressDialog.setCanceledOnTouchOutside(false);
		progressDialog.setTitle("Parse XML File !");
		progressDialog.show();

		super.onPreExecute();
	}

	@Override
	protected void onPostExecute(String result) {
		Message message = new Message();
		message.what = 1;
		Bundle bundle = new Bundle();

		bundle.putString("container", result);
		message.setData(bundle);

		handler.sendMessage(message);
		progressDialog.dismiss();
		super.onPostExecute(result);
	}

}
